package be.dch.util;

import java.io.IOException;
import java.io.OutputStream;

import org.apache.log4j.Logger;
import org.apache.log4j.Priority;

/**
 * 
 * @author EH053
 * 
 */
public class Log4jOutputStream extends OutputStream {

    private static final Logger LOG = Logger.getLogger(Log4jOutputStream.class);

    private final transient Priority prior;

    /**
     * 
     * @param L
     */
    public Log4jOutputStream(final Priority prior) {
	super();
	this.prior = prior;

    }

    @Override
    public void write(final int b) throws IOException {
	Log4jOutputStream.LOG.log(this.prior, String.valueOf((char) b));
    }

    @Override
    public void write(final byte[] b, final int off, final int len) throws IOException {
	final String out = new String(b, off, len);
	if (!out.equalsIgnoreCase("\r\n")) {
	    Log4jOutputStream.LOG.log(this.prior, out);
	}
    }

    @Override
    public void write(final byte[] b) throws IOException {
	this.write(b, 0, b.length);
    }

}
